package com.nidu.demo.notice.model;

import com.alibaba.cola.exception.BizException;
import com.nidu.demo.base.BaseDeletableEntity;
import com.nidu.demo.base.BaseStatusEntity;
import com.nidu.demo.base.BaseTenantEntity;
import com.nidu.demo.common.enums.BooleanEnum;
import com.nidu.demo.common.enums.StatusEnum;
import com.nidu.demo.common.exception.ErrorCodeConstants;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * 通知公告领域实体
 *
 * @author auto
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
public class Notice extends BaseTenantEntity implements BaseStatusEntity, BaseDeletableEntity {

    private Long id;

    /**
     * 公告标题
     */
    private String title;

    /**
     * 公告内容
     */
    private String content;

    /**
     * 公告类型（1通知 2公告）
     */
    private Integer type;

    /**
     * 公告状态（0正常 1关闭）
     */
    private Integer status;

    /**
     * 是否删除
     */
    private Boolean deleted;

    @Override
    public void isDeleted() {
        if (BooleanEnum.TRUE.getValue().equals(this.getDeleted())) {
            throw new BizException(ErrorCodeConstants.NOTICE_NOT_FOUND.getCode(), ErrorCodeConstants.NOTICE_NOT_FOUND.getMessage());
        }
    }

    @Override
    public void isDisable() {
        if (StatusEnum.DISABLE.getValue().equals(this.status)) {
            throw new BizException(ErrorCodeConstants.NOTICE_STATUS_DISABLE.getCode(), ErrorCodeConstants.NOTICE_STATUS_DISABLE.getMessage());
        }
    }

    public static Notice create(String title, String content, Integer type) {
        Notice notice = new Notice();
        notice.setTitle(title)
                .setContent(content)
                .setType(type);
        return notice;
    }

    public static Notice update(Long id, String title, String content, Integer type) {
        Notice notice = new Notice();
        notice.setId(id)
                .setTitle(title)
                .setContent(content)
                .setType(type);
        return notice;
    }
}
